package com.example.hp.qingyi.compass.fragment.fragment.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.hp.qingyi.R;
import com.example.hp.qingyi.compass.fragment.fragment.base.HotspotBaseData;
import com.example.hp.qingyi.compass.fragment.fragment.hotspotadapter.HotspotOneAdapter;
import com.example.hp.qingyi.compass.fragment.fragment.hotspotadapter.HotspotTwoAdapter;

import java.util.List;


/**
 * Created by A on 2018/11/7.
 */

public class HotspotFragmentAdapter extends RecyclerView.Adapter{

    /**
     * 首部
     */
    public static final int RV_ONE = 0;

    /**
     * 第二部分
     */
    public static final int RV_TWO = 1;

    /**
     * 第三部分
     */
    public static final int RV_THREE = 2;

    /**
     * 第四部分
     */
    public static final int RV_FOUR = 3;

    /**
     * 第五部分
     */
    public static final int RV_FIVE = 4;

    /**
     * 第六部分
     */
    public static final int RV_SIX = 5;

    /**
     * 当前类型
     */
    private int currentType = 0;

    private Context context;
    private List<HotspotBaseData.DataBean> dataBean;
    private LayoutInflater inflater;


    public HotspotFragmentAdapter(Context context, List<HotspotBaseData.DataBean> dataBean) {
        this.context = context;
        this.dataBean = dataBean;
        inflater = LayoutInflater.from(context);
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        if (viewType == RV_ONE){
            return new HotspotOneViewHolder(context,inflater.inflate(R.layout.hotspot_one,null));
        } else if (viewType == RV_TWO){
            return new HotspotTwoViewHolder(context,inflater.inflate(R.layout.hotspot_two,null));
        }
        return null;
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        if (getItemViewType(position) == RV_ONE){
            HotspotOneViewHolder hotspotOneViewHolder = (HotspotOneViewHolder) holder;
            hotspotOneViewHolder.setData(dataBean);
        } else if (getItemViewType(position) == RV_TWO){
            HotspotTwoViewHolder hotspotTwoViewHolder= (HotspotTwoViewHolder) holder;
            hotspotTwoViewHolder.setData(dataBean);
        }
    }


    /**
     * 第一部分
     */
    class HotspotOneViewHolder extends RecyclerView.ViewHolder{
        private Context context;
        private RecyclerView recyclerView;
        private HotspotOneAdapter hotspotOneAdapter;

        public HotspotOneViewHolder(final Context context, View ItemView) {
            super(ItemView);
            this.context = context;
            this.recyclerView = itemView.findViewById(R.id.radio_one);
        }

        public void setData(List<HotspotBaseData.DataBean> data) {
            //得到数据了，要去设置GridView适配器
            hotspotOneAdapter = new HotspotOneAdapter(data,context);
            recyclerView.setLayoutManager(new GridLayoutManager(context,1));
            recyclerView.setAdapter(hotspotOneAdapter);
        }
    }



    /**
     * 第二部分
     */
    class HotspotTwoViewHolder extends RecyclerView.ViewHolder{
        private Context context;
        private RecyclerView recyclerView;
        private HotspotTwoAdapter hotspotTwoAdapter;

        public HotspotTwoViewHolder(final Context context, View ItemView) {
            super(ItemView);
            this.context = context;
            this.recyclerView = itemView.findViewById(R.id.radio_two);
        }

        public void setData(List<HotspotBaseData.DataBean> data) {
            //得到数据了，要去设置GridView适配器
            hotspotTwoAdapter = new HotspotTwoAdapter(data,context);
            recyclerView.setLayoutManager(new GridLayoutManager(context,1));
            recyclerView.setAdapter(hotspotTwoAdapter);
        }
    }

    @Override
    public int getItemCount() {
        return 2;
    }

    /**
     * 得到类型
     *
     * @param position
     * @return
     */
    @Override
    public int getItemViewType(int position) {

        switch (position) {
            case RV_ONE:
                currentType = RV_ONE;
                break;
            case RV_TWO:
                currentType = RV_TWO;

                break;
            case RV_THREE:
                currentType = RV_THREE;

                break;
            case RV_FOUR:
                currentType = RV_FOUR;

                break;
            case RV_FIVE:
                currentType = RV_FIVE;

                break;
            case RV_SIX:
                currentType = RV_SIX;

                break;
            default:
                break;
        }
        return currentType;
    }
}
